package 力扣日常刷题.木22二月.第13天219;

import java.util.ArrayList;

/**
 * @author 帅小伙
 * @date 2022/2/19
 * @description
 */
public class Demo92和为正数的连续序列 {

    public int[][] findContinuousSequence(int target) {
        ArrayList<int[]> ans = new ArrayList<>();

        for (int l = 1, r = 2; l < r; ) {
            int sum = (l + r) * (r - l + 1) / 2;
            if(sum == target) {
                int[] res = new int[r - l + 1];
                for (int i = l; i <= r; i++) res[i - l] = i;
                ans.add(res);
                l++;
            } else if(sum < target) r++;
            else l++;
        }
        // 返回二维数组的方法
        return ans.toArray(new int[ans.size()][]);
    }

}
